package com.bzyd.cloud.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.bzyd.cloud.service.impl.OrderServiceImpl3;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * OrderController3，测试sentinel
 * Created by Xianyue Dang on 2021/4/28
 */
@RestController
@Slf4j
public class OrderController3 {


    //直接使用jar命令启动项目(控制台本身是一个SpringBoot项目)
    //java -Dserver.port=8080 -Dcsp.sentinel.dashboard.server=localhost:8080 -Dproject.name=sentinel-dashboard -
    //jar sentinel-dashboard-1.7.0.jar

    //注意：因为Sentinel采用延迟加载，只有在主动发起一次请求后，才会被拦截并发送给服务端。

    @Autowired
    private OrderServiceImpl3 orderServiceImpl3;

    @RequestMapping("/order/message1")
    public String message1() throws Exception {
        return orderServiceImpl3.message();
    }


    @RequestMapping("/order/message2")
    public String message2() throws Exception {
        return orderServiceImpl3.message2();
    }

    //测试热点参数流控规则
    @RequestMapping("/order/message3")
    @SentinelResource("message3")
    public String message3(String name, Integer age) {
        return name + age;
    }

}
